ORGANIZATION_BLOCK OB 100
BEGIN

	// Check if OB-temp writing is enabled
	__FEATURE	1
	L		0
	<>D
	SPB isen

	// Enable OB-temp presets
	__FEATURE	1,	1
	// Reboot
	CALL		SFC -2 (
		REBOOT_TYPE := 1
	)

isen:	NOP		0

END_ORGANIZATION_BLOCK


ORGANIZATION_BLOCK OB 1
VAR_TEMP
	OB1_EV_CLASS		: BYTE;
	OB1_SCAN_1		: BYTE;
	OB1_PRIORITY		: BYTE;
	OB1_OB_NUMBR		: BYTE;
	OB1_RESERVED_1		: BYTE;
	OB1_RESERVED_2		: BYTE;
	OB1_PREV_CYCLE		: INT;
	OB1_MIN_CYCLE		: INT;
	OB1_MAX_CYCLE		: INT;
	OB1_DATE_TIME		: DATE_AND_TIME;
END_VAR
BEGIN

	L		#OB1_EV_CLASS
	__ASSERT==	__ACCU 1,	B#16#11

	L		#OB1_SCAN_1
	__ASSERT==	__ACCU 1,	B#16#03

	L		#OB1_PRIORITY
	__ASSERT==	__ACCU 1,	B#16#01

	L		#OB1_OB_NUMBR
	__ASSERT==	__ACCU 1,	B#16#01

	L		#OB1_RESERVED_1
	__ASSERT==	__ACCU 1,	B#16#00

	L		#OB1_RESERVED_2
	__ASSERT==	__ACCU 1,	B#16#00

	L		#OB1_PREV_CYCLE
	__ASSERT<=	__ACCU 1,	W#16#7FFF

	L		#OB1_MIN_CYCLE
	__ASSERT<=	__ACCU 1,	W#16#7FFF

	L		#OB1_MAX_CYCLE
	__ASSERT<=	__ACCU 1,	W#16#7FFF

	LAR1		P##OB1_DATE_TIME
	L		B [AR1, P#0.0]	// year
	T		MB 0
	CALL		FC 1 (BCD_BYTE := MB 0)
	__ASSERT>=	MB 0,		B#16#13
	L		B [AR1, P#1.0]	// month
	T		MB 0
	CALL		FC 1 (BCD_BYTE := MB 0)
	__ASSERT<=	MB 0,		B#16#12
	L		B [AR1, P#2.0]	// day
	T		MB 0
	CALL		FC 1 (BCD_BYTE := MB 0)
	__ASSERT<=	MB 0,		B#16#31
	L		B [AR1, P#3.0]	// hour
	T		MB 0
	CALL		FC 1 (BCD_BYTE := MB 0)
	__ASSERT<=	MB 0,		B#16#24
	L		B [AR1, P#4.0]	// minute
	T		MB 0
	CALL		FC 1 (BCD_BYTE := MB 0)
	__ASSERT<=	MB 0,		B#16#60
	L		B [AR1, P#5.0]	// second
	T		MB 0
	CALL		FC 1 (BCD_BYTE := MB 0)
	__ASSERT<=	MB 0,		B#16#60
	L		B [AR1, P#6.0]	// millisecond upper
	T		MB 0
	CALL		FC 1 (BCD_BYTE := MB 0)
	L		B [AR1, P#7.0]	// millisecond lower / weekday
	T		MB 0
	CALL		FC 1 (BCD_BYTE := MB 0)
	L		MB 0
	UD		DW#16#0000000F
	__ASSERT>=	__ACCU 1,	1
	__ASSERT<=	__ACCU 1,	7

	__ASSERT<=	#OB1_PREV_CYCLE,	#OB1_MAX_CYCLE
	__ASSERT>=	#OB1_PREV_CYCLE,	#OB1_MIN_CYCLE
	__ASSERT>=	#OB1_MAX_CYCLE,		#OB1_MIN_CYCLE


	CALL SFC 46 // STOP CPU
END_ORGANIZATION_BLOCK


FUNCTION FC 1 : VOID
TITLE = Check whether BCD_BYTE is a valid BCD value
VAR_INPUT
	BCD_BYTE	: BYTE;
END_VAR
BEGIN
	L		#BCD_BYTE
	UD		DW#16#0000000F
	__ASSERT<=	__ACCU 1,	9
	L		#BCD_BYTE
	SRD		4
	UD		DW#16#0000000F
	__ASSERT<=	__ACCU 1,	9
END_FUNCTION
